<template>
  <page-header-wrapper>
    <global-search :list="searchList" @search="handleSearch" @reset="handleReset"> </global-search>
    <a-card :bordered="false">
      <s-table ref="table" size="default" :rowKey="(record, index) => index" :columns="columns" :data="loadData">
        <span slot="index" slot-scope="text, record, index"> {{ index + 1 }} </span>
        <span slot="time" slot-scope="text">{{ text | moment }}</span>
        <div slot="action" slot-scope="text, record">
          <y-button
            type="link"
            @click="handleDownload(record.exportDownFileName)"
            :disabled="$isEmpty(record.exportDownFileName)"
            >下载</y-button
          >
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { exportDataList } from '@/api/dataComparison'
import { downloadEvt } from '@/utils/util'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
  },
  data() {
    return {
      queryParam: {
        strContent: {},
      },
      searchList: [
        {
          label: '任务名称',
          fields: 'exportName',
          type: 'input',
          props: {
            placeholder: '请输入任务名称',
          },
        },
        {
          label: '比对类型',
          fields: 'exportCategory',
          type: 'select',
          props: {
            placeholder: '请选择比对类型',
            options: [
              { label: '现售备案房产信息比对', value: '现售备案房产信息比对' },
              { label: '公租房信息比对', value: '公租房信息比对' },
              { label: '保障成员比对', value: '保障成员比对' },
              { label: '婚姻比对', value: '婚姻比对' },
              { label: '保障家庭比对', value: '保障家庭比对' },
              { label: '商品房信息比对', value: '商品房信息比对' },
              { label: '预售备案房产信息比对', value: '预售备案房产信息比对' },
            ],
          },
        },
        {
          label: '比对时间',
          fields: 'time',
          type: 'range',
          props: {
            valueFormat: 'YYYY-MM-DD HH:mm:ss',
            showTime: { format: 'HH:mm' },
            format: 'YYYY-MM-DD HH:mm',
          },
        },
      ],
      columns: [
        {
          title: '序号',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '任务名称',
          align: 'center',
          dataIndex: 'exportName',
        },
        {
          title: '比对时间',
          align: 'center',
          dataIndex: 'lexportDate',
          scopedSlots: { customRender: 'time' },
        },
        {
          title: '比对类型',
          align: 'center',
          dataIndex: 'exportCategory',
        },
        {
          title: '数据条数',
          align: 'center',
          dataIndex: 'exportNum',
        },
        {
          title: '比对结果下载',
          align: 'center',
          width: '180px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return exportDataList(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleSearch(values) {
      if (values.time) {
        values.Start = values.time[0]
        values.End = values.time[1]
      }
      delete values.time
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDownload(path) {
      const start = path.lastIndexOf('/')
      const end = path.lastIndexOf('.')
      const url = path.replaceAll('~', process.env.VUE_APP_API_BASE_URL)
      downloadEvt(url, path.substring(start + 1, end))
    },
  },
}
</script>
<style lang="less" scoped></style>
